package com.fyl.oauth2.dao;

import com.fyl.oauth2.domain.ClientEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ClientMapper {
    @Select("SELECT * FROM registered_client WHERE client_id = #{clientId}")
    ClientEntity findByClientId(@Param("clientId") String clientId);

    @Select("SELECT * FROM registered_client WHERE id = #{id}")
    ClientEntity findById(@Param("id") Long id);

    @Select("SELECT * FROM registered_client")
    List<ClientEntity> findAll();

    @Insert("INSERT INTO registered_client (id, client_id, client_secret, scopes, redirect_uris, authorization_grant_types, client_authentication_methods) " +
            "VALUES (#{id}, #{clientId}, #{clientSecret}, #{scopes}, #{redirectUris}, #{authorizationGrantTypes}, #{clientAuthenticationMethods})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(ClientEntity clientEntity);
}
